<?php
include_once('../../app/connection.php');

if(isset($_POST['action']))
{
    $action = $_POST['action'];
    
    if($action == "check_magv")
    {
        if(isset($_POST['magv']))
        {
            $magv = $_POST['magv'];
            $sql = "SELECT * FROM giaovien WHERE MAGIAOVIEN='".$magv."'";
            $result = mysql_query($sql);
            if(mysql_num_rows($result) != 0)        
                echo '<span style="color:red"><i>'.$magv.' đã tồn tại</i></span>';
            else if($magv != '') echo '<span style="color:green"><i>'.$magv.' chưa có</i></span>';
        }
    }
    
    if($action == "add_gv")
    {
        if(isset($_POST['magv']))
        {
            $magv = $_POST['magv'];
			$p = md5("123456");
            $hoten = $_POST['hoten'];
            $makhoa = $_POST['khoa'];
            $ngaysinh = $_POST['ngaysinh'];
            $gioitinh = $_POST['gioitinh'];
			$pw = md5('123456');
            //$sql = "INSERT INTO `giaovien`(MAGIAOVIEN, HOTEN, GIOITINH, NGAYSINH, MAKHOA, PASSWORD, TRANGTHAI) VALUES                     ('$magv','$hoten','$gioitinh','$namsinh','$makhoa','$p','1')";
            $sql = "INSERT INTO `giaovien`(MAGIAOVIEN, PASSWORD, HOTEN, GIOITINH, NGAYSINH, MAKHOA, TRANGTHAI) VALUES 
                    ('$magv','$pw','$hoten','$gioitinh','$ngaysinh','$makhoa','1')";
            $result = mysql_query($sql) or die("co loi");
            
            echo "Đã thêm ".$magv;
        }
    }
}

?>